package com.wyclabs.cardmaker;
import javafx.beans.property.SimpleStringProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 * @author TylerW
 * @date 06/21/21 3:05 PM
 */
@Data
@AllArgsConstructor
public class Card {

    private SimpleStringProperty name;

    private SimpleStringProperty type;

    private SimpleStringProperty lv;

    private SimpleStringProperty cost;

    private SimpleStringProperty atk;

    private SimpleStringProperty hp;

    private SimpleStringProperty tag;

    private SimpleStringProperty path;

    private SimpleStringProperty desc;

    public Card(String name, String type) {
        this.name = new SimpleStringProperty(name);
        this.type = new SimpleStringProperty(type);
    }

    public Card(String name, String type, String lv, String cost,
                String atk, String hp, String tag, String path,
                String desc) {
        this.name = new SimpleStringProperty(name);
        this.type = new SimpleStringProperty(type);
        this.lv = new SimpleStringProperty(lv);
        this.cost = new SimpleStringProperty(cost);
        this.atk = new SimpleStringProperty(atk);
        this.hp = new SimpleStringProperty(hp);
        this.tag = new SimpleStringProperty(tag);
        this.path = new SimpleStringProperty(path);
        this.desc = new SimpleStringProperty(desc);
    }

    public Card(Row row) {
        this.name = new SimpleStringProperty(row.getCell(0).getStringCellValue());
        this.type = new SimpleStringProperty(row.getCell(1).getStringCellValue());
        this.lv = new SimpleStringProperty(row.getCell(2).getStringCellValue());
        this.cost = new SimpleStringProperty(getNumericValue(row.getCell(3)));
        this.atk = new SimpleStringProperty(getNumericValue(row.getCell(4)));
        this.hp = new SimpleStringProperty(getNumericValue(row.getCell(5)));
        this.tag = new SimpleStringProperty(row.getCell(6).getStringCellValue());
        // this.path = new SimpleStringProperty(row.getCell(7).getStringCellValue());
        this.desc = new SimpleStringProperty(row.getCell(7).getStringCellValue());
    }

    private String getNumericValue(Cell cell) {
        if (StringUtils.isBlank(cell.toString())) {
            return "";
        } else {
            return String.valueOf(Double.valueOf(cell.getNumericCellValue()).intValue());
        }
    }

}
